package com.tutu.user.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.tutu.common.GlobalConstants;
import com.tutu.user.dao.SysUserGroupMapper;
import com.tutu.user.entity.SysUserGroup;
import com.tutu.user.entity.SysUserGroupExample;
import com.tutu.user.entity.SysUserGroupExample.Criteria;
import com.tutu.user.service.ISysUserGroupService;

@Service("sysUserGroupService")
public class SysUserGroupServiceImpl implements ISysUserGroupService {
	@Resource
	private SysUserGroupMapper sysUserGroupMapper;
	
	@Override
	public List<SysUserGroup> getSysUserGroup(SysUserGroup sysUserGroup) {
		SysUserGroupExample sysUserGroupExample = new SysUserGroupExample();
		Criteria criteria = sysUserGroupExample.createCriteria();
		List<String> aliveFlags = new ArrayList<String>();
		aliveFlags.add(GlobalConstants.FLAG_ENABLE);
		aliveFlags.add(GlobalConstants.FLAG_PROTECT);
		criteria.andAliveFlagIn(aliveFlags);
		sysUserGroupExample.setOrderByClause("CREATE_TIME DESC");
		List<SysUserGroup> sysUserGroups = this.sysUserGroupMapper.selectByExample(sysUserGroupExample);
		return sysUserGroups;
	}

	@Override
	public void saveSysUserGroup(SysUserGroup sysUserGroup) {
		this.sysUserGroupMapper.insert(sysUserGroup);
	}

	@Override
	public SysUserGroup getSysUserGroup(String groupId) {
		return this.sysUserGroupMapper.selectByPrimaryKey(groupId);
	}

	@Override
	public void updateSysUserGroup(SysUserGroup sysUserGroup) {
		this.sysUserGroupMapper.updateByPrimaryKeySelective(sysUserGroup);
	}

	@Override
	public void deleteSysUserGroup(String groupId) throws Exception {
		this.sysUserGroupMapper.deleteByPrimaryKey(groupId);
	}

}
